<template>
	<view class="page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<pageTxt>
			<z-paging ref="paging" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<view class="navbar-box">
						<u-navbar title="上传整改内容" :autoBack="true" :fixed="false"></u-navbar>
					</view>
				</template>
				<view class="add-content ios">
					<u--form labelPosition="top" :model="tjRuleForm" ref="uForm" labelWidth="auto">
						<view class="form-box">
							<u-form-item labelPosition="top" labelWidth="100%" required label="整改内容" borderBottom>
								<u--textarea
									disableDefaultPadding
									v-model="tjRuleForm.rectification_description"
									border="none"
									placeholder="输入整改内容"
									:placeholderStyle="{ fontSize: '13.5px', color: '#BFC4CC' }"
								></u--textarea>
							</u-form-item>

							<u-form-item labelPosition="top" labelWidth="100%" required label="整改文件 (.jpg,.png,.gif)">
								<file-upload :type="1" @afterRead="afterRead" @delete="deletePic"></file-upload>
							</u-form-item>
						</view>
					</u--form>
				</view>
				<view class="footer ios">
					<u-button
						text="提交"
						@click="submit"
						customStyle="width: 702rpx;height: 88rpx;background: #3B75FF;border-radius: 16rpx;font-weight: 500;font-size: 28rpx;color: #FFFFFF;margin:20rpx 24rpx;"
					></u-button>
				</view>
			</z-paging>
		</pageTxt>
	</view>
</template>

<script>
export default {
	data() {
		return {
			loading: false,
			tjRuleForm: {
				rectification_id: '',
				rectification_description: '',
				rectification_file: []
			}
		};
	},
	onLoad(option) {
		this.tjRuleForm.rectification_id = option.id;
	},
	methods: {
		afterRead(files) {
			files.map((item) => {
				let obj = {
					url: item.url
				};
				this.tjRuleForm.rectification_file.push(obj);
			});
		},
		deletePic(e) {
			this.tjRuleForm.rectification_file.splice(e.index, 1);
		},
		async submit() {
			let tjRuleForm = this.tjRuleForm;
			if (!tjRuleForm.rectification_description) {
				uni.showToast({
					title: '请输入整改内容',
					icon: 'error'
				});
				return;
			}
			if (!tjRuleForm.rectification_file.length) {
				uni.showToast({
					title: '请选择整改文件',
					icon: 'error'
				});
				return;
			}
			let data = {
				rectification_id: tjRuleForm.rectification_id,
				rectification_description: tjRuleForm.rectification_description
			};
			uni.showLoading({
				title: '文件上传中',
				mask: true
			});
			let rectification_file = await this.$upload(tjRuleForm.rectification_file);
			uni.hideLoading();
			data.rectification_file = rectification_file.arrResult;
			this.submitRectification(data);
		},
		// 提交整改
		submitRectification(data) {
			uni.showLoading({
				title: '信息提交中',
				mask: true
			});
			this.$Apipc.submitRectification(data).then((res) => {
				console.log(res, '提交整改');
				uni.hideLoading();
				if (res.code == 200) {
					setTimeout(() => {
						var currentPages = getCurrentPages()[getCurrentPages().length - 2]
						if (currentPages) {
							uni.navigateBack({
								delta: 1
							});
						} else {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					}, 500);
				}
				uni.showToast({
					title: res.code == 200 ? '操作成功' : res.message,
					icon: res.code == 200 ? 'success' : 'error'
				});
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
